package com.nidu.demo.tenant.executor.query;

import com.alibaba.cola.dto.MultiResponse;
import com.nidu.demo.tenant.convertor.TenantPackageCriteriaConvertor;
import com.nidu.demo.tenant.dto.TenantPackageListQry;
import com.nidu.demo.tenant.convertor.TenantPackageConvertor;
import com.nidu.demo.tenant.dto.TenantPackageCO;
import com.nidu.demo.tenant.gateway.TenantPackageGateway;
import com.nidu.demo.tenant.model.TenantPackage;
import com.nidu.demo.tenant.model.TenantPackageCriteria;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 租户套餐列表查询执行器
 *
 * @author auto
 */
@Component
@RequiredArgsConstructor
public class TenantPackageListQryExe {

    private final TenantPackageGateway gateway;

    private final TenantPackageConvertor convertor;

    private final TenantPackageCriteriaConvertor criteriaConvertor;

    public MultiResponse<TenantPackageCO> execute(TenantPackageListQry qry) {
        // 1. 查询数据
        TenantPackageCriteria criteria = criteriaConvertor.toDataObject(qry);
        List<TenantPackage> tenantPackages = gateway.listByCondition(criteria);

        // 2. 转换为DTO返回
        List<TenantPackageCO> tenantPackageCOs = tenantPackages.stream()
                .map(convertor::toClientObject)
                .collect(Collectors.toList());

        return MultiResponse.of(tenantPackageCOs);
    }
}
